﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web.MainPage.Basic.SalesInfo
{
    public partial class ListInfo : BasePage
    {
        private static readonly CardLogistics.DAL.Basic.Basic_SalesInfoData DALSales = new DAL.Basic.Basic_SalesInfoData();
        protected void Page_Load(object sender, EventArgs e)
        {
            wuc_toolbar.DeleteEvent += new EventHandler(DeleteUC);
            if (!IsPostBack)
            {
                BindRpt(0);
            }
        }

        /// <summary>
        /// 绑定Rpt数据
        /// </summary> 
        /// <param name="pageIndex"></param>
        private void BindRpt(int pageIndex)
        {
            int recordCount = 0;
            int pageCount = 0;
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("v_basic_salesinfo", "ID", " LASTUPDATEDATE ", AspNetPager1.PageSize, pageIndex, " ISDELETE=0 ", "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt(AspNetPager1.CurrentPageIndex);
        }

        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteUC(object sender, EventArgs e)
        {
            string delId = hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                string errInfo = "";
                for (int i = 0; i < ids.Length; i++)
                {
                    string resStr = DALSales.Delete(int.Parse(ids[i]));
                    if (resStr.Split(',')[0] == "ok")
                        resCount++;
                    else if (resStr.Split(',')[0] == "err")
                    {
                        errInfo += resStr.Split(',')[1] + "\n";
                    }
                }
                BindRpt(1);
            }
        }
    }
}